<html>
<head><meta charset="utf-8"><title>Passing native libraries when producing rlib · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Passing.20native.20libraries.20when.20producing.20rlib.html">Passing native libraries when producing rlib</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224450370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Passing%20native%20libraries%20when%20producing%20rlib/near/224450370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Marcel Hlopko <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Passing.20native.20libraries.20when.20producing.20rlib.html#224450370">(Jan 29 2021 at 10:03)</a>:</h4>
<p>Hi all,<br>
I'm looking into rules_rust for Bazel and I noticed they currently pass all transitive native libraries to rustc (for example as <code>-lstatic=c++</code>) when producing rlib artifact. Is that necessary? Is rustc going to use them? My little project builds fine without them, but I might just be lucky :)</p>
<p>Thank you!</p>



<a name="224461587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Passing%20native%20libraries%20when%20producing%20rlib/near/224461587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Passing.20native.20libraries.20when.20producing.20rlib.html#224461587">(Jan 29 2021 at 12:05)</a>:</h4>
<p>That ensures that when a rust executable is produced, those static libraries are linked in.</p>



<a name="224462970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Passing%20native%20libraries%20when%20producing%20rlib/near/224462970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Marcel Hlopko <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Passing.20native.20libraries.20when.20producing.20rlib.html#224462970">(Jan 29 2021 at 12:23)</a>:</h4>
<p>Oh so when an rlib crate depends on a native library, the crate will remember the flag that needs to be passed when linking the binary? Therefore when linking the binary I don't need to pass the flag manually?</p>



<a name="224464925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Passing%20native%20libraries%20when%20producing%20rlib/near/224464925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Passing.20native.20libraries.20when.20producing.20rlib.html#224464925">(Jan 29 2021 at 12:45)</a>:</h4>
<p>That is roughly it. For dylibs this is exactly correct, but for staticlibs, they are included into the generated<code>.rlib</code> directly as far as I know unless the unstable <code>static-nobundle</code> kind is used.</p>



<a name="224478694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Passing%20native%20libraries%20when%20producing%20rlib/near/224478694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Marcel Hlopko <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Passing.20native.20libraries.20when.20producing.20rlib.html#224478694">(Jan 29 2021 at 14:38)</a>:</h4>
<p>I'll try to read up on that, thank you! But if the build system I'm using is already tracking native libraries, I could not pass them on the library compilation, but only on binary linking, and it might work. How fragile do you think this approach is?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>